package com.liu.interceptor;

import com.liu.domain.teacher;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Created by liu on 17-11-28.
 */
public class TeacherIntercepor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o) throws Exception {
        HttpSession session = httpServletRequest.getSession();
        Object teacher = session.getAttribute("user");
       /* int t = 0;*/
        if (teacher != null) {
            return true;
        }
        httpServletResponse.sendRedirect("http://127.0.0.1:8080/dor/tiaozhuan");
        /*httpServletRequest.getRequestDispatcher("/login").forward(httpServletRequest, httpServletResponse);*/
       /* t =1;*/
        return false;
    }

    @Override
    public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {

    }

    @Override
    public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {

    }
}
